﻿using System;
using System.IO;

namespace OfficeMiddlewareCore
{
    public class FileHelper
    {
        private FileHelper()
        {

        }
        private static FileHelper _fileHelper;
        public static FileHelper Instace
        {
            get
            {
                if (_fileHelper == null)
                {
                    _fileHelper = new FileHelper();
                }
                return _fileHelper;
            }
        }

        public string GenerateFilePath(string extName, string docCode = null, string fileDirectory = null)
        {
            var tempFolder = string.IsNullOrWhiteSpace(fileDirectory) ? System.IO.Path.GetTempPath() : fileDirectory;
            if (Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
            }
            var filePath = Path.Combine(tempFolder, $"{docCode ?? Guid.NewGuid().ToString("N")}");
            if (!string.IsNullOrWhiteSpace(extName))
            {
                filePath += $"{extName}";
            }
            return filePath;
        }
        public bool Exists(string fileName)
        {
            var tempFolder = System.IO.Path.GetTempPath();
            var filePath = Path.Combine(tempFolder, fileName);
            return File.Exists(filePath);
        }
    }
}
